package com.chen.reggie.config;

import org.springframework.cache.annotation.CachingConfigurerSupport;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.StringRedisSerializer;

/**
 * @ClassName RedisConfig
 * @Description TODO
 * @Author hainc
 * @Date 2022/9/11 9:51
 * @Version 1.0
 **/
//redis配置类：配置序列化方式
@Configuration
public class RedisConfig extends CachingConfigurerSupport {

    @Bean
    public RedisTemplate<Object,Object> redisTemplate(RedisConnectionFactory connectionFactory){
        RedisTemplate<Object, Object> redisTemplate = new RedisTemplate<>();

        //默认的key序列化器为：jdkSerializationRedisSerializer
        redisTemplate.setKeySerializer(new StringRedisSerializer());//设置key的序列化为String方式
        redisTemplate.setHashValueSerializer(new StringRedisSerializer());//设置hashkeyValue的序列化

        redisTemplate.setConnectionFactory(connectionFactory);

        return redisTemplate;

    }
}
